//
//  CommunityViewController.m
//  BigJoy
//
//  Created by new-1020 on 2017/6/12.
//  Copyright © 2017年 Rowling. All rights reserved.
//

#import "CommunityViewController.h"
#import "XMIndexHeaderView.h"
#import "DynamicCellViewModel.h"
#import "DynamicCell.h"
#import "FeedBackVC.h"
#import "DynamicDetailViewController.h"
#import "DynamicListViewController.h"
#import "TopRankListVC.h"
typedef enum {
    NEW,
    HOT,
    CARE,
    TOP
} TableType;

@interface CommunityViewController ()<XMIndexHeaderViewDelegate>
@property (nonatomic,assign) TableType TableType;
@property (nonatomic,strong) NSArray *vcArray;
@property (nonatomic,strong) UIView *contentView;
@end

@implementation CommunityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"社区";
    [self setUI];
}

-(void)setUI {
    UIButton * btn = [[UIButton alloc]init];
    [btn setImage:[UIImage imageNamed:@"scan1"] forState:UIControlStateNormal];
    [btn sizeToFit];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    UIButton * btn2 = [[UIButton alloc]init];
    [btn2 setImage:[UIImage imageNamed:@"jia_hong"] forState:UIControlStateNormal];
    [btn2 sizeToFit];
    // 跳转到发表动态
    @weakify(self);
    [[btn2 rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        FeedBackVC * vc = [FeedBackVC new];
        vc.isShequ = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn2];
    self.hideNavLine = YES;
    XMIndexHeaderView * indexHeaderView = [[XMIndexHeaderView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 33) WithTitleArray:@[@"最新",@"热门",@"关注",@"TOP50"] animation:NO];
    [self.view addSubview:indexHeaderView];
    indexHeaderView.font = [UIFont systemFontOfSize:14];
    indexHeaderView.lineColor = [UIColor blackColor];
    indexHeaderView.lineWidth = SCREEN_WIDTH / 4;
    indexHeaderView.selectFontColr = [UIColor colorForHex:@"333333"];
    indexHeaderView.fontColor = [UIColor colorForHex:@"999999"];
    indexHeaderView.delegateXM = self;
    UIView * lineView = [[UIView alloc]init];
    [self.view addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.height.equalTo(@1);
        make.top.equalTo(indexHeaderView.mas_bottom);
    }];
    lineView.backgroundColor = XMColor(221, 221, 221);
    self.contentView = [UIView new];
    [self.view addSubview:self.contentView];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(indexHeaderView.mas_bottom).offset(1);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-50);
    }];
    DynamicListViewController * vc1 = [[DynamicListViewController alloc]init];
    DynamicListViewController * vc2 = [[DynamicListViewController alloc]init];
    DynamicListViewController * vc3 = [[DynamicListViewController alloc]init];
    TopRankListVC             * vc4 = [[TopRankListVC alloc]init];
    [self addChildViewController:vc1];
    [self addChildViewController:vc2];
    [self addChildViewController:vc3];
    [self addChildViewController:vc4];
    self.vcArray = @[vc1,vc2,vc3,vc4];
    [self XMIndexHeaderViewDidselectedWithIndex:0];
}

// xmdelegate
-(void)XMIndexHeaderViewDidselectedWithIndex:(NSInteger)index {
    UIViewController * vc = (UIViewController *)self.vcArray[index];
    [self.contentView addSubview:vc.view];
    [vc.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView);
    }];
    switch (index) {
        case 0:
        {
            // 最新
            self.TableType = NEW;
        }
            break;
        case 1:
        {
            //热门
            self.TableType = HOT;

        }
            break;
        case 2:
        {
            //关注
            self.TableType = CARE;

        }
            break;
        case 3:
        {
            //TOP50
            self.TableType = TOP;
        }
            break;
            
        default:
            break;
    }
}

@end
